package cn.keepme.ep.constants;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import cn.keepme.ep.question.entity.FQuestionEntity;
import cn.keepme.ep.question.entity.FQuestionOptionEntity;

public class Constants {

	public static List<FQuestionEntity> getRandom(List<FQuestionEntity> obj, int n){
		List<FQuestionEntity> object = new ArrayList<FQuestionEntity>();
		Random rand = new Random();
		boolean[] bol = new boolean[obj.size()];
		int randint = 0;
		FQuestionEntity entity = null;
		for(int i=0;i<n;i++){
			do{
				randint = rand.nextInt(obj.size());
			}while(bol[randint]);
			
			bol[randint] = true;
			
			entity = new FQuestionEntity();
			entity = obj.get(randint);
			object.add(entity);
		}
		return object;
	}
	
	public static List<FQuestionOptionEntity> getRandomOptions(List<FQuestionOptionEntity> obj, int n){
		List<FQuestionOptionEntity> object = new ArrayList<FQuestionOptionEntity>();
		Random rand = new Random();
		boolean[] bol = new boolean[obj.size()];
		int randint = 0;
		FQuestionOptionEntity entity = null;
		for(int i=0;i<n;i++){
			do{
				randint = rand.nextInt(obj.size());
			}while(bol[randint]);
			
			bol[randint] = true;
			
			entity = new FQuestionOptionEntity();
			entity = obj.get(randint);
			object.add(entity);
		}
		return object;
	}
	
	public static String[] getRandom(String[] obj, int n){
		String[] object = new String[n];
		Random rand = new Random();
		boolean[] bol = new boolean[obj.length];
		int randint = 0;
//		FQuestionEntity entity = null;
		for(int i=0;i<n;i++){
			do{
				randint = rand.nextInt(obj.length);
			}while(bol[randint]);
			
			bol[randint] = true;
			
			object[i] = obj[randint];
		}
		return object;
	}
	
	public static String getNumber(int n){
		String str = "";
		if(n<10){
			str = "000"+n;
		}else if(n>=10&&n<100){
			str = "00"+n;
		}else if(n>=100&&n<1000){
			str = "0"+n;
		}else{
			str = n+"";
		}
		return str;
	}
}
